package demo;

public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        Object lockerA=new Object();
        Object lockerB=new Object();
        Thread t1=new Thread(()->{
            synchronized (lockerA){
                synchronized (lockerB){
                    System.out.println("t1");
                }
            }
        });
        Thread t2=new Thread(()->{
            //按照一定的顺序进行加锁就可以避免循环等待
            synchronized (lockerA) {
                synchronized (lockerB) {
                    System.out.println("t2");
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
